<extend name="Public/base" />
<block name="content">
<div id="content">
	<div id="content-header">
		<div id="breadcrumb">
			<a href="{:U('Index/index')}" title="首页" class="tip-bottom"><i
				class="icon-home"></i> 首页</a> <a href="{:U('Auth/index')}"
				class="tip-bottom">权限管理</a><a href="javascript:void(0);"
				class="current">{$meta_title}</a>
		</div>
	</div>
	<div class="container-fluid">
		<br>
		<div class="row-fluid">
			<div class="span12">
				<div class="widget-box">
					<!-- <div class="widget-content "> -->
					<div class="widget-title">
						<ul class="nav nav-tabs">
							<li class="active" style="width: 100px; text-align: center;"><a
								href="javascript:void(0);">访问授权</a></li>
							<!-- <li style="width: 100px; text-align: center;"><a
								href="{:U('category',array('group_id'=>I('group_id')))}">分类授权</a></li> -->
							<li style="width: 100px; text-align: center;"><a
								href="{:U('user',array('group_id'=>I('group_id')))}">成员授权</a></li>
						</ul>
					</div>
					<!-- 访问授权 -->
					<div class="tab-pane in">
						<form class="form-horizontal auth-form">
							<volist name="node_list" id="node">
							<dl class="checkmod">
								<dt class="hd">
									<label class="checkbox"><input
										class="auth_rules rules_all" type="checkbox" name="rules[]"
										value="{$node.id}">{$node.title}管理</label>
								</dt>
								<dd class="bd">
									<present name="node['child']"> <volist
										name="node['child']" id="child">
									<div class="rule_check">
										<div>
											<label class="checkbox"<notempty name="child['tip']">title='{$child.tip}'</notempty>>
												<input class="auth_rules rules_row" type="checkbox"
												name="rules[]"
												value="<?php echo $auth_rules[$child['url']] ?>" />{$child.title}
											</label>
										</div>
										<notempty name="child['operator']"> <span
											class="divsion"> </span> <span class="child_row"> <volist
												name="child['operator']" id="op"> <label
												class="checkbox"<notempty name="op['tip']">title='{$op.tip}'</notempty>>
												<input class="auth_rules" type="checkbox" name="rules[]"
												value="<?php echo $auth_rules[$op['url']] ?>" />{$op.title}
											</label> </volist>
										</span> </notempty>
									</div>
									</volist> </present>
								</dd>
							</dl>
							</volist>

							<input type="hidden" name="id" value="{$this_group.id}" />
							<button type="submit" class="btn btn-success ajax-post"
								url="{:U('auth')}" target-form="auth-form">确 定</button>
							<button class="btn btn-danger"
								onclick="javascript:history.back(-1);return false;">返 回</button>
						</form>
					</div>

					<!-- </div> -->
				</div>
			</div>
			<div class="row-fluid"></div>
		</div>
	</div>
	<script type="text/javascript" src="__STATIC__/qtip/jquery.qtip.min.js"></script>
	<link rel="stylesheet" type="text/css"
		href="__STATIC__/qtip/jquery.qtip.min.css" media="all">
	<script type="text/javascript" charset="utf-8">
    +function($){
        var rules = [{$this_group.rules}];
        $('.auth_rules').each(function(){
            if( $.inArray( parseInt(this.value,10),rules )>-1 ){
                $(this).prop('checked',true);
            }
            if(this.value==''){
                $(this).closest('span').remove();
            }
            
        });
        //全选节点
        $('.rules_all').on('change',function(){
        	if(this.checked){
        		$(this).closest('dl').find('dd').find('input').parent('span').addClass("checked");
        	}else{
        		$(this).closest('dl').find('dd').find('input').parent('span').removeClass("checked");
        	}
			$(this).closest('dl').find('dd').find('input').prop('checked',this.checked);
        });
        $('.rules_row').on('change',function(){
        	if(this.checked){
        		$(this).closest('.rule_check').find('.checkbox').find('input').parent('span').addClass("checked").find("input").attr("checked","checked");
        		/* $(this).closest('dl').find('dd').find('input').parent('span').addClass("checked"); */
        	}else{
        		/* $(this).closest('dl').find('dd').find('input').parent('span').removeClass("checked"); */
        		$(this).closest('.rule_check').find('.checkbox').find('input').parent('span').removeClass("checked").find("input").removeAttr("checked");
        	}
        	
         	/* if($(this).closest('dl').find('dd').find('input').parent('span')){
        		$(this).closest('dl').find('dd').find('input').parent('span').removeClass('checked');
        	}else{
        		$(this).closest('dl').find('dd').find('input').parent('span').addClass('checked');
        	}
            $(this).closest('.rule_check').find('.child_row').find('input').prop('checked',this.checked); */ 
        });
        
		$(".checkbox").on("change", function () {
			var parent = $(this).closest(".child_row");
			var checkRowLength = parent.find(".checkbox").index();
				parent.find(".checkbox").each(function (i) {
					if ($(this).find(".checker span input")[0].checked) {
						parent.closest(".rule_check").find("div .checker span").addClass("checked").find("input").attr("checked","checked");
						return false;
					} else {
						if (i == checkRowLength) {
							parent.closest(".rule_check").find("div .checker span").removeClass("checked").find("input").removeAttr("checked");
					}
	               } 
				});
				

        }); 

        
		
        var check_obj = null
        $('.checkbox').each(function(){
        	//默认设置
        	/* check_obj = $(this).find(":checked")
            if(check_obj.val() > 0 ){
            	if(check_obj.attr('class') == 'auth_rules rules_row'){
            		$(this).parents('.rule_check').find('input:checkbox').attr('checked','checked')
            	}
            } */
        	//
            $(this).qtip({
                content: {
                    text: $(this).attr('title'),
                    title: $(this).text()
                },
                position: {
                    my: 'bottom center',
                    at: 'top center',
                    target: $(this)
                },
                style: {
                    classes: 'qtip-dark',
                    tip: {
                        corner: true,
                        mimic: false,
                        width: 10,
                        height: 10
                    }
                }
            });

        });

    }(jQuery);
</script>
	<script type="text/javascript">
highlight_subnav("{:U('Auth/index')}");
</script>
</block>
